package org.lennon.service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.lennon.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component("taskJob")
public class TaskJob {
	@Autowired
	private ParseLog parse;

	@Scheduled(cron = "0 0 1 * * ?")
	public void job1() {
		Date date = new Date();
		// date.setDate(date.getDay()-1);
		Calendar rightNow = Calendar.getInstance();
		rightNow.setTime(date);
		rightNow.add(Calendar.DAY_OF_YEAR, -1);
		Date dt1 = rightNow.getTime();

		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式

		String project = StringUtil.getProperties("conf/project", "project.name");
		String logPath = StringUtil.getProperties("conf/project", "project.logpath");

		String fileName = logPath + df.format(dt1) + ".txt";
		parse.saveLogFileHistory(fileName);
		parse.loadFromFile(project,fileName );
		
		parse.loadFromFile(project, fileName);
		System.out.println("任务进行中。。。");
	}
}
